#include "mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::on_IC_comboBox_1_currentIndexChanged(int index)
{
    QString AB[8] = {" A A A", " A A B", " A B A", " B A A", " A B B", " B A B", " B B A", " B B B"};
    ui->IC_AB_1->setText(AB[index]);
}

void MainWindow::on_IC_comboBox_2_currentIndexChanged(int index)
{
    QString AB[8] = {" A A A", " A A B", " A B A", " B A A", " A B B", " B A B", " B B A", " B B B"};
    ui->IC_AB_2->setText(AB[index]);
}

void MainWindow::on_IC_comboBox_3_currentIndexChanged(int index)
{
    QString AB[8] = {" A A A", " A A B", " A B A", " B A A", " A B B", " B A B", " B B A", " B B B"};
    ui->IC_AB_3->setText(AB[index]);
}

void MainWindow::on_IC_comboBox_4_currentIndexChanged(int index)
{
    QString AB[8] = {" A A A", " A A B", " A B A", " B A A", " A B B", " B A B", " B B A", " B B B"};
    ui->IC_AB_4->setText(AB[index]);
}

void MainWindow::on_IC_comboBox_5_currentIndexChanged(int index)
{
    QString AB[8] = {" A A A", " A A B", " A B A", " B A A", " A B B", " B A B", " B B A", " B B B"};
    ui->IC_AB_5->setText(AB[index]);
}

QString MainWindow::getComplStr(int pos)
{
    bool* compl = da.getComplement(pos - 1);

    QString a = "";
    QString b = "";

    for(int i = 0; i < 10; i++)
    {
        if(compl[i])
            a += QString::number(i);
        else
            b += QString::number(i);
    }

    delete[] compl;

    QString result = "(" + a +")A/(" + b + ")B";

    return result;
}

void MainWindow::on_IC_lineEdit_1_editingFinished()
{
    QString t = ui->IC_lineEdit_1->text();
    int index = t.toInt();

    QString complStr = "";

    if( ! ( (0 < index) && (index < 127) ) )
        ui->IC_lineEdit_1->clear();
    else
        complStr = getComplStr(index);

    ui->Compl_label_1->setText(complStr);
}

void MainWindow::on_IC_lineEdit_2_editingFinished()
{
    QString t = ui->IC_lineEdit_2->text();
    int index = t.toInt();

    QString complStr = "";

    if( ! ( (0 < index) && (index < 127) ) )
        ui->IC_lineEdit_2->clear();
    else
        complStr = getComplStr(index);

    ui->Compl_label_2->setText(complStr);
}

void MainWindow::on_IC_lineEdit_3_editingFinished()
{
    QString t = ui->IC_lineEdit_3->text();
    int index = t.toInt();

    QString complStr = "";

    if( ! ( (0 < index) && (index < 127) ) )
        ui->IC_lineEdit_3->clear();
    else
        complStr = getComplStr(index);

    ui->Compl_label_3->setText(complStr);
}

void MainWindow::on_IC_lineEdit_4_editingFinished()
{
    QString t = ui->IC_lineEdit_4->text();
    int index = t.toInt();

    QString complStr = "";

    if( ! ( (0 < index) && (index < 127) ) )
        ui->IC_lineEdit_4->clear();
    else
        complStr = getComplStr(index);

    ui->Compl_label_4->setText(complStr);
}

void MainWindow::on_IC_lineEdit_5_editingFinished()
{
    QString t = ui->IC_lineEdit_5->text();
    int index = t.toInt();

    QString complStr = "";

    if( ! ( (0 < index) && (index < 127) ) )
        ui->IC_lineEdit_5->clear();
    else
        complStr = getComplStr(index);

    ui->Compl_label_5->setText(complStr);
}

void MainWindow::on_iscompute_but_clicked()
{
    int index[5];
    int AB[5];
    index[0] = ui->IC_lineEdit_1->text().toInt();
    index[1] = ui->IC_lineEdit_2->text().toInt();
    index[2] = ui->IC_lineEdit_3->text().toInt();
    index[3] = ui->IC_lineEdit_4->text().toInt();
    index[4] = ui->IC_lineEdit_5->text().toInt();

    int count = 0;
    for( int i = 0; i < 5; i++ )
    {
        if(index[i] == 0)
            continue;

        index[count] = index[i];
        count++;
    }
    if(count < 3)
        return;


    //Clear all the information

    for(int i = 0; i < count - 2; i++)
        for(int j = i + 1; j < count - 1; j++)
            for(int k = j + 1; k < count; k++)
            {

            }

}
